package controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import po.Course;
import service.CourseService;


@Controller
public class courseController {
	
	// 依赖注入
	@Autowired
	private CourseService courseService;	
	@RequestMapping(value = "/course/getCourse.action")
	public String list( Model model) {
		List<Course> courselist = courseService.getCourseList();
		model.addAttribute("courselist", courselist);	
		return "course_list";

	}
	@RequestMapping("/course/delCourse.action")
	public String courseDelete(Integer courseid) {
		int rows = courseService.deleteCourse(courseid);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/course/getCourse.action";
	}
	@RequestMapping("/course/addCourse.action")
	public String courseAdd(Course course) {
		int rows = courseService.addCourse(course);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/course/getCourse.action";
	}
	
	@RequestMapping(value ="/course/getcourseId.action")
	@ResponseBody
	public Course getCourseId(Integer id) {
		Course data = courseService.getCourseId(id);
		return data;
   }  
	
	@RequestMapping(value ="/course/updateCourse.action")
	@ResponseBody
	public String updateCourse(Course course) {
		int row = courseService.updateCourse(course);
		if(row>0) {
			return "OK";
		}else {
			return "false";
		}
   } 
}
